<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>

<script>
    var arr=[5,2,3,7,1,1,8,9,4,0,6,10];
    function pop(arr){
        var length=arr.length;
        for(var i= 0;i<length-1;i++){
            var exchange=false;
            for(var j= 0;j<length-i-1;j++){
                if(arr[j]>arr[j+1]){
                    var max=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=max;
                    exchange=true;
                }
            }
            if(!exchange)break;
            console.log(i,arr);
        }
        return arr;
    }

    console.info(pop(arr));
</script>

</body>
</html>